// +build block

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
)

func grade(score int) string {
	var g string

	switch {
	case score > 100 || score < 0:
		panic(fmt.Sprintf("error score: %d", score))
	case score >= 90:
		g = "A"
	case score >= 80:
		g = "B"
	case score >= 60:
		g = "C"
	case score >= 0:
		g = "D"
	}

	return g
}

func switchFunc(grade string) {
	switch grade {
	case "A":
		fmt.Println(grade)
	case "B":
		fmt.Println(grade)
	}
}

func forFunc() {
	for i := 0; i < 100; i++ {
		fmt.Println(i)
	}

	// 死循环
	for true {
		fmt.Println("xdxx")
		break
	}

	var result string
	for n := 10; n > 0; n /= 2 {
		lsb := n % 2
		result = strconv.Itoa(lsb) + result
	}
}

func printFile(filename string) {
	file, err := os.Open(filename)
	if err != nil {
		panic(err)
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}

func add(x int, y int) int { return x + y }

//func add(x, y int) int     { return x + y }
//func add(x, y int) (z int) { z = x + y; return }
//func add(int, int) int     { return 0 }
//func add(x int, _ int) int { return x + 0 }

func main() {
	const filename = "test"
	if buff, err := ioutil.ReadFile(filename); err != nil {
		fmt.Printf("read file<%s> error: %s\n", filename, err)
	} else {
		fmt.Println(string(buff))
	}

	fmt.Println(grade(81))
	switchFunc(grade(81))

	printFile("test")
}
